package com.feidee.bigdata.controller;

import com.feidee.bigdata.service.ConsumerService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:CHQ
 * @Date:2020/4/15 9:36
 * @Description
 */
@RestController
//@DefaultProperties(defaultFallback = "commonFallBack")  //全局服务降级通配标签
public class ConsumerController {

    @Autowired
    private ConsumerService consumerService;

    @RequestMapping("/ok")
    //服务降级（客户端超过最大等待时间3s或此方法执行出错，都将进入兜底方法okHanel）
    @HystrixCommand(fallbackMethod = "okHandel", commandProperties =
            {@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "3000")})
    public String ok() {
        return consumerService.ok();
    }

    public String okHandel() {
        return "您好，系统繁忙，请稍等重试~";
    }

    @RequestMapping("/err")
    public String err() {
        return consumerService.err();
    }
    /*public String commonFallBack(){
        return "您好，系统繁忙，请稍后重试~~~~~";
    }*/
}
